<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false"%>
<c:set var="cp" scope="session" value="${pageContext.request.servletContext.contextPath}"/>

	<div class="you fl">
					<div class="my clearfix">
						<h2 class="fl">我的订单</h2>
						<a href="#" class="fl">请谨防钓鱼链接或诈骗电话，了解更多&gt;</a>
					</div>
					<div class="dlist clearfix">
						<ul class="fl clearfix" id="wa">
							<li class="on"><a href="#2">全部有效订单</a></li>
							<li><a href="#2">待支付</a></li>
							<li><a href="#2l">待收货</a></li>
							<li><a href="#2">已关闭</a></li>
						</ul>
						<form action="#" method="get" class="fr clearfix">
							<input type="text" name="" id="" value="" placeholder="请输入商品名称、订单号" />
							<input type="button" name="" id="" value="" />
						</form>
					</div>
					
					<div id="orderlist"></div>
					
					<div id="userPagination" class="pagination">
						<a href="#" class="first" data-action="first">&laquo;</a>
					    <a href="#" class="previous" data-action="previous">&lsaquo;</a>
					    <a href="#" class="next" data-action="next">&rsaquo;</a>
					    <a href="#" class="last" data-action="last">&raquo;</a>
					</div>
				</div>
				
				<link rel="stylesheet" type="text/css" href="${cp}/css/jqpagination.css">
				<script type="text/javascript" src="${cp}/js/jquery.jqpagination.js"></script>
				
				<script type="text/javascript">
					var currentPage = 1;
					var maxPage = ${totalpage};
					$(document).ready(function() {
						//初始化分页插件
						init();
						listOrder();
					});
					
					function init() {
						$('#userPagination').jqPagination({
						    paged: function(page) {
						    	currentPage = page;
						    	listOrder();
						    },
						    max_page : maxPage,
						    current_page : currentPage
						});
					};
					
					function listOrder() {
						$.ajax({
						    url:'${cp}/order/listOrder.do',
						    type:'POST', //GET
						    data:{
						    	currentPage : currentPage
						    },
						    timeout:5000,    //超时时间
						    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
						    success:function(data){
						    	
						    	if (data.success) {
						    		var results = data.data.data;
						    		var totalPage = data.data.totalpage;
						    		
						    		var orderHtml = '';
						    		for (var i=0;i<results.length;i++) {
						    			var result = results[i];
						    			orderHtml += '<div class="dkuang">';
						    			orderHtml += '<p class="one">'+result.statusDesc +'</p>';
						    			orderHtml += '<div class="word clearfix">';
						    			orderHtml += '<ul class="fl clearfix">';
						    			orderHtml += '<li>'+result.createTime +'</li>';
						    			orderHtml += '<li>'+result.realName+'</li>';
						    			orderHtml += '<li>订单号:'+result.id +'</li>';
						    			orderHtml += '<li>'+result.payType+'</li>';
						    			orderHtml += '</ul>';
						    			orderHtml += '<p class="fr">订单金额：<span>'+result.amount+'</span>元</p>';
						    			orderHtml += '</div>';
						    			orderHtml += '<div class="shohou clearfix">';
						    			orderHtml += '<a href="#" class="fl"><img src="${cp }/images/usercenter/img/g1.jpg"/></a>';
						    			orderHtml += '<p class="fl"><a href="#">'+result.goodTile+'</a><a href="#">'+result.unitPrice+'</a></p>';
						    			orderHtml += '<p class="fr">';
						    			orderHtml += '<a href="${cp }/order/toOrderDetail.do?orderId='+result.id+'" target="_blank">订单详情</a>';
						    			if (result.status == 0) {
						    				orderHtml += '<a href="###" onclick="toPay('+result.id+');">去支付</a>';
						    			}
						    			orderHtml += '</p>';
						    			
						    			orderHtml += '</div>';
						    			orderHtml += '</div>';
						    		}
						    		
						    		$("#orderlist").html(orderHtml);
						    		maxPage = totalPage;
						    	}
						    },
						    error:function(xhr,textStatus){
						        console.log('错误')
						        console.log(xhr)
						        console.log(textStatus)
						    },
						    complete:function(){
						        console.log('结束')
						    }
						});
					}
					
					function toPay(orderId) {
						$.ajax({
							 url:'${cp}/order/toPay.do',
							    type:'POST', //GET
							    data:{
							    	orderId : orderId
							    },
							    timeout:5000,    //超时时间
							    dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
							    success:function(data){
							    	if(!data.success) {
							    		alert(data.message);
							    		return false;
							    	}
							    	
							    	window.location.href = data.data.payOrderUrl;
							    	
							    },
							    error:function(xhr,textStatus){
							        console.log('错误')
							        console.log(xhr)
							        console.log(textStatus)
							    },
							    complete:function(){
							        console.log('结束');
							        addressFlag = true;
							    }
						});
					}
				</script>